package cn.fkj233;

import org.json.JSONObject;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

public class Test {
    public static void main(String[] args) {
        //获取文件
        String filePath = "C:\\hotfix\\4.0.0\\OSRELAndroid3.4.0.json"; // 文件路径

        try (BufferedReader br = new BufferedReader(new FileReader(filePath))) {
            String line;
            StringBuilder jsonContent = new StringBuilder();

            while ((line = br.readLine()) != null) {
                jsonContent.append(line);
            }

            String jsonData = jsonContent.toString();
            // 在这里处理读取到的 JSON 数据
            //System.out.println(jsonData);
            JSONObject jsonObject = new JSONObject(jsonData);
            JSONObject json = jsonObject.getJSONObject("region_info");
            String DataUrl = json.getString("data_url");
            String ResourceUrl = json.getString("resource_url");
            int lastIndex = DataUrl.lastIndexOf("/");
            String DataUrlBak = DataUrl.substring(lastIndex + 1);
            String ResourceUrlBak = DataUrlBak;
            int ClientDataVersion = json.getInt("client_data_version");
            int ClientSilenceDataVersion = json.getInt("client_silence_data_version");
            String ClientVersionSuffix = json.getString("client_version_suffix");
            String ClientSilenceVersionSuffix = json.getString("client_silence_version_suffix");
            String ClientDataMd5 = json.getString("client_data_md5");
            String ClientSilenceDataMd5 = json.getString("client_silence_data_md5");
            System.out.println();
            System.out.println("DataUrlBak: " + DataUrlBak);
            System.out.println("ResourceUrlBak: " + ResourceUrlBak);
            System.out.println("DataUrl: " + DataUrl);
            System.out.println("ResourceUrl: " + ResourceUrl);
            System.out.println("ClientDataVersion: " + ClientDataVersion);
            System.out.println("ClientSilenceDataVersion: " + ClientSilenceDataVersion);
            System.out.println("ClientVersionSuffix: " + ClientVersionSuffix);
            System.out.println("ClientSilenceVersionSuffix: " + ClientSilenceVersionSuffix);
            System.out.println("ClientDataMd5: " + ClientDataMd5);
            System.out.println("ClientSilenceDataMd5: " + ClientSilenceDataMd5);
            System.out.println();
            JSONObject ResVersionConfig = json.getJSONObject("res_version_config");
//            boolean Relogin = ResVersionConfig.getBoolean("Relogin");
            boolean Relogin = false;
            int Version = ResVersionConfig.getInt("version");
            String VersionSuffix = ResVersionConfig.getString("version_suffix");
            String Branch = ResVersionConfig.getString("branch");
            String ReleaseTotalSize = ResVersionConfig.getString("release_total_size");
            String Md5 = ResVersionConfig.getString("md5");

            System.out.println("Relogin: " + Relogin);
            System.out.println("Version: " + Version);
            System.out.println("VersionSuffix: " + VersionSuffix);
            System.out.println("Branch: " + Branch);
            System.out.println("ReleaseTotalSize: " + ReleaseTotalSize);
            System.out.println("Md5: " + Md5);


        } catch (IOException e) {
            e.printStackTrace();
        }
//        JSONObject jsonObject = new JSONObject("{\n" +
//                "  \"regionInfo\": {\n" +
//                "    \"PayCallbackUrl\": \"http://127.0.0.1/pay-callback\",\n" +
//                "    \"AreaType\": \"CN\",\n" +
//                "    \"CdkeyUrl\": \"http://127.0.0.1\",\n" +
//                "    \"PrivacyPolicyUrl\": \"\",\n" +
//                "    \"FeedbackUrl\": \"\",\n" +
//                "    \"BulletinUrl\": \"\",\n" +
//                "    \"SecretKey\": \"\",\n" +
//                "    \"ResourceUrl\": \"https://autopatchcn.yuanshen.com/client_game_res/4.0_live\",\n" +
//                "    \"DataUrl\": \"https://autopatchcn.yuanshen.com/client_design_data/4.0_live\",\n" +
//                "    \"ResourceUrlBak\": \"4.0_live\",\n" +
//                "    \"DataUrlBak\": \"4.0_live\",\n" +
//                "    \"ClientDataVersion\": 17476732,\n" +
//                "    \"ClientSilenceDataVersion\": 17331021,\n" +
//                "    \"ClientDataMd5\": \"{\\\"remoteName\\\": \\\"data_versions\\\", \\\"md5\\\": \\\"1e79fc101f28ba17796481603e923084\\\", \\\"fileSize\\\": 5148}\",\n" +
//                "    \"ClientSilenceDataMd5\": \"{\\\"remoteName\\\": \\\"data_versions\\\", \\\"md5\\\": \\\"f6287b67d005680a2b032a7a6ffa4276\\\", \\\"fileSize\\\": 410}\",\n" +
//                "    \"ClientVersionSuffix\": \"50c9f341ea\",\n" +
//                "    \"ClientSilenceVersionSuffix\": \"d455244a33\",\n" +
//                "    \"ResVersionConfig\": {\n" +
//                "      \"Relogin\": false,\n" +
//                "      \"Md5\": \"{\\\"remoteName\\\": \\\"res_versions_external\\\", \\\"md5\\\": \\\"d8c628461baa1a9574ef32ee6b19d485\\\", \\\"fileSize\\\": 499387}\\r\\n{\\\"remoteName\\\": \\\"res_versions_medium\\\", \\\"md5\\\": \\\"21e31b93ce485a4ecc7d29daf59e8fa6\\\", \\\"fileSize\\\": 57798}\\r\\n{\\\"remoteName\\\": \\\"res_versions_streaming\\\", \\\"md5\\\": \\\"668561402c7a8d42a5aeea7f8e8dfaed\\\", \\\"fileSize\\\": 2124}\\r\\n{\\\"remoteName\\\": \\\"base_revision\\\", \\\"md5\\\": \\\"7c0a3453e69c4f308a04df3520dfc92a\\\", \\\"fileSize\\\": 19}\",\n" +
//                "      \"Version\": 17445512,\n" +
//                "      \"ReleaseTotalSize\": \"0\",\n" +
//                "      \"VersionSuffix\": \"53a0fc142e\",\n" +
//                "      \"Branch\": \"4.0_live\"\n" +
//                "    }\n" +
//                "  },\n" +
//                "  \"StopServer\": {\n" +
//                "    \"StopBeginTime\": 1577808000,\n" +
//                "    \"StopEndTime\": 1893427200,\n" +
//                "    \"Url\": \"https://vme50.icu/\",\n" +
//                "    \"ContentMsg\": \"芜湖起飞\"\n" +
//                "  }\n" +
//                "}");
//        String text = jsonObject.getJSONObject("regionInfo").getString("PayCallbackUrl");
//        System.out.println("PayCallbackUrl: " + text);
    }
}
